<template>
  <div></div>
</template>

<script>
import {getInfo} from "@/api/login";
import Cookies from "js-cookie";

export default {
  name: "LoginSso",
  data() {
    return {
      loginRules: {},
      loading: false,
      //验证码开关
      captchaOnOff: true,
      //注册开关
      register: false,
      //重定向
      redirect: undefined
    };
  },
  watch: {
  },
  created() {
    //页面初始化时调单点登录方法
    this.loginSso();
  },
  methods: {
    loginSso(){
      //获取地址栏中的code
      const code = this.$route.query.code;
      const utype = this.$route.query.utype;
      console.log("code="+code)
      console.log("utype="+utype)
      //调用登录的接口
      if(code==''||code==undefined||code==null){
        //请求中不带code，拦截为正常登录
      }else{
        this.loading = true;//开启过渡动画
        const loginInfo = {
          "code" : code
        };
        //执行另一套登录操作
        //不是本系统的用户,去J平台登陆去
        this.$store.dispatch("LoginSso", loginInfo).then(() => {
          Cookies.set('userType', utype, { expires: 30 });
          this.$router.push({ path: this.redirect || "/" }).catch(() => { });
          // this.$message.success("登录成功");
          // this.loading = false;
          // //判断当前角色
           getInfo().then((res) => {
          //   //获取角色名称
          //   var rolesName = res.roles[0];
          //   //获取所属场馆
          //   this.deptInfo = res.dept;
            sessionStorage.setItem("ssUserName", res.user.nickName);
          //   //处理登录
          //   this.$router.push({path: this.redirect || "/"}).catch(() => {});
           });
        }).catch(err=> {
          this.$store.dispatch('LogOut').then(() => {
          location.href = '/';
        })
          // console.log("有异常信息",err);
          // this.loading = false;
        });
      }
    },
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">

</style>
